package com.runen.infinitemovement.activity;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.runen.infinitemovement.Constant;
import com.runen.infinitemovement.R;
import com.runen.infinitemovement.base.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Create by LiaoDuanHong
 * Create on 2020/09/14 11:40
 */
public class AboutAppActivity extends BaseActivity {
    @BindView(R.id.top_btn_left)
    Button topBtnLeft;
    @BindView(R.id.top_title)
    TextView topTitle;
    @BindView(R.id.top_btn_right)
    Button topBtnRight;
    @BindView(R.id.top_iv_right)
    ImageView topIvRight;
    @BindView(R.id.tv_versions)
    TextView tvVersions;
    @BindView(R.id.tv_phone)
    TextView tv_phone;
    @BindView(R.id.tv_api)
    TextView tv_api;
    @BindView(R.id.tv_web_api)
    TextView tv_web_api;
    private PackageManager pm;
    private PackageInfo pi = null;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_about_app;
    }

    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {
        ButterKnife.bind(this);
        topTitle.setText("关于");

        pm = getPackageManager();

        if (Constant.BASE_HOST.equals("https://i.a.futmarch.cn/")) {
            tv_api.setVisibility(View.GONE);
        } else {
            tv_api.setText(Constant.BASE_HOST);
        }
        if (Constant.BASE_HOST_H5.equals("https://h5.futmarch.cn/")) {
            tv_web_api.setVisibility(View.GONE);
        } else {
            tv_web_api.setText(Constant.BASE_HOST_H5);
        }

        try {
            pi = pm.getPackageInfo(getPackageName(), 0);
            String versionName = pi.versionName;
            tvVersions.setText(versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }


    @OnClick({R.id.top_btn_left, R.id.tv_phone})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.top_btn_left:
                finish();
                break;
            case R.id.tv_phone:
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_DIAL);
                intent.setData(Uri.parse("tel:" + tv_phone.getText().toString()));
                startActivity(intent);
                break;
        }
    }
}
